home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / C / BoulderEngine / source / geras / BOULDER.C next >
Encoding:
C/C++ Source or Header  |  1998-03-30  |  8.8 KB  |  344 lines

  1. /* =================================================================
  2.    =  BOULDER DASH MAIN BODY. ©1993 by SAVELSOFTWARE inc.          =
  3.    =  Idea: Peter Liepa., C coding: Levas Vabolis.                 =
  4.    =  (In Fact real BOULDER DASH is © by First Star Soft. )        =
  5.    ================================================================= */
  6. #include "BOULDER0.C" /* graphics */
  7. #include "BOULDER3.C" /* man */
  8. #include "LEVELS.C"   /* Lygiai */
  9. #include "ROTATE.C"   /* color cycle */
  10. /* #include "music.c"*/ /* Sound routines V1.0 or higher */
  11. STATIC UBYTE bummx[50],bummy[50],bummi[50],Adz,Adb,GREITIS;
  12. STATIC USHORT BUMPOINT,clos,fillalready,oldclos,levl,MAXLEVL;
  13. STATIC ULONG HSCORE;
  14. SHORT NextLevel();
  15. titrai()
  16. {
  17. SetAPen(&rastport,5L); RectFill(&rastport,63L,0L,799L,11L);
  18. PrntI(70,1,16); PrntI(80,1,18); PrntI(130,1,10); PrntI(140,1,11);
  19. PrntI(150,1,12); PrntI(160,1,13); PrntI(170,1,5); PrntI(180,1,18);
  20. PrntI(230,1,5); PrntI(240,1,14); PrntI(250,1,0); PrntI(260,1,15);
  21. PrntI(270,1,13); PrntI(280,1,18); PrntI(360,1,17); PrntI(370,1,11);
  22. PrntI(380,1,5); PrntI(390,1,14); PrntI(400,1,0); PrntI(410,1,15);
  23. PrntI(420,1,13); PrntI(430,1,18); PrntL(440,1,HSCORE);
  24. PrntI(510,1,11); PrntI(520,1,16); PrntI(530,1,18);
  25. Prnt(540,1,ITEMS);  PrntI(580,1,14); PrntI(590,1,12); PrntI(600,1,18);
  26. Prnt(610,1,levl); Prnt(190,1,LIVES); PrntL(290,1,SCORE); Prnt(90,1,0);
  27. }
  28. main()
  29. {
  30.  MAXLEVL=maximum();
  31.  levl=0; GREITIS=5;
  32.  pasiruosk(); WaitTOF(); AudioON();
  33.  scena(&rastport); Makegraphics(); titrai();
  34.  PrntI(70,1,10); Prnt(90,1,GREITIS);
  35.  while(pekb(0xBFEC00)!=117)
  36.  {
  37.    rotate();
  38.    if(man2())
  39.    {
  40.     if(levl>0 && hx==-1) { levl--; }
  41.     if(levl<MAXLEVL && hx==1) {levl++; }
  42.     Prnt(610,1,levl); Delay(7); rotate(); Delay(6); rotate();
  43.     if(GREITIS>0 && hy==-1) {GREITIS--; }
  44.     if(GREITIS<20 && hy==1) {GREITIS++; }
  45.     PrntI(70,1,10); Prnt(90,1,GREITIS);
  46.    }
  47.    if(fire())
  48.    {
  49.     LIVES=2;
  50.     Play(); Audiopirst2(0); scena(&rastport); Makegraphics(); titrai();
  51.     PrntI(70,1,10); Prnt(90,1,GREITIS);
  52.    }
  53.    Delay(1);
  54.  }
  55. AudioOFF(); for(levl=0;levl<126;levl++) {rotate(); }
  56. Delay(2);
  57. FMemory(); exit();
  58. } /* End of Main */
  59. Play()
  60. {
  61. SHORT n,x,y,i,j,l;
  62. BUMPOINT=0; HSCORE=10000; FINISH=0;
  63. level(levl); SCORE=0;
  64. SetRast(&rastport,0L); Makegraphics();
  65. show();
  66. titrai(); ALIVE=15;
  67. fillalready=0; oldclos=0;
  68. for(n=TIM;n>0;n--) {   ALIVE--; for(l=0;l<GREITIS;l++) {WaitTOF();}
  69.   bumm2();
  70.   for(x=0;x<29;x++) {
  71.    for(y=12;y>=0;y--) { j++;
  72.      if(Adz && j<70) { --Adz; Audiodzin2(Adz);}
  73.      if(Adb && j>70 && j<140){ --Adb; Audiopirst2(Adb);}
  74.                     
  75.     if (k(x,y)<9)
  76.        analize(x,y);
  77.     else { k(x,y)=k(x,y)/10; }
  78.    } /* NEXT Y */
  79.   }  /* NEXT X */
  80.   j=0;
  81.   if(Adzin) {Audiodzin(); Adz=64; Adzin=0;}
  82.   if(Abum) {Audiopirst(); Abum=0; Adb=64; }
  83.   if(!oldclos) { fillalready=1; }
  84.   if(oldclos>HMAGMA && !fillalready) { ffill(); }
  85.   if(!clos && !fillalready) { ffill(); }
  86.   oldclos=0; clos=0;
  87.   if(!ALIVE) { if(LIVES>0) {LIVES--; ALIVE=15; Death(); n=TIM; } }
  88.   Prnt(90,1,n/10); PrntL(290,1,SCORE);
  89.   Prnt(540,1,ITEMS);
  90.   if(!LIVES && !ALIVE) { n=0; }
  91.   i=pekb(0xbfec00);
  92.   if(i==117 || n<2)           /* ESC klavisas */
  93.    {
  94.     n=0;
  95.     if(LIVES>0)
  96.      {
  97.       WaitTOF(); LIVES--; n=TIM; Prnt(190,1,LIVES);
  98.       Death();
  99.      }
  100.    }
  101.   if(FINISH){ LIVES++; n=NextLevel(n); oldclos=0; fillalready=0; }
  102.   rotate();
  103. }    /* NEXT N */
  104.  
  105. Delay(5);
  106. hide();
  107. Delay(50);
  108.  
  109. } /* End of Play */
  110.  
  111. SHORT NextLevel(m)
  112. SHORT m;
  113. {
  114. SHORT i,n=0;
  115.  Audiodzin();
  116.  for(i=m;i>0;i-=20) {
  117.      SCORE+=10; PrntL(290,1,SCORE);
  118.      rotate();
  119.      if(n)
  120.       Audiopip(10);
  121.      else
  122.       {Audiodzin2(10); }
  123.        n=!n;
  124.                     } Audiodzin2(0);
  125.  if(SCORE>HSCORE) {HSCORE=SCORE; PrntL(440,1,HSCORE);}
  126.  levl++; if(levl>MAXLEVL) {levl=0;}
  127.  Delay(50); hide(); level(levl); show(); titrai(); Delay(10);
  128.  FINISH=0; return(TIM);
  129. } /* end of n=NextLevel(n) */
  130. Death()
  131. {
  132.   Audiopirst2(0); Delay(60); hide(); level(levl); show(); titrai();
  133.   fillalready=0; oldclos=0;
  134. }
  135. ffill()
  136. {
  137. SHORT x,y,fff=3;
  138.  
  139. fillalready=1;
  140. if(oldclos>CRISTAL) {fff=2;}
  141. for(x=1;x<30;x++)
  142.  {
  143.   for(y=1;y<12;y++)
  144.    {
  145.     if(e(x,y)==6) {set(x,y,fff); }
  146.    }
  147.  }
  148. }
  149. analize(x,y)  /* <<<<<<<<< Pati rimciausia paprograme >>>>>>>>>>>>> */
  150. SHORT x,y;
  151. {
  152. LONG kq,jj;
  153. SHORT q,c1,c2,c3,c4,p,kz,i,j,bb,zz,uzz,manhere,os;
  154. SHORT ez[5];
  155. q=e(x,y);
  156. if (q==10) { man(x,y); ALIVE++; return; }
  157. if(q==9 && !ITEMS) {set(x,y,0); WaitTOF(); set(x,y,11);
  158.   WaitTOF(); WaitTOF(); set(x,y,9); e(x,y)=12; }
  159. if(q<2) { return; }
  160. if(q==7) {return; }
  161. c1=x+1; c2=x-1; c3=y-1; c4=y+1;
  162. p=e(x,c4);
  163. if (q==14 && k(x,y)==2){bumm(x,c3,0); detonate(x,c3);return;}
  164. if (q==2 || q==3)
  165.  {
  166.   if (p==0) { set(x,c4,q); set(x,y,0); k(x,c4)=1; return; }
  167.   if (k(x,y)>0) { /* kinetinis sokas */
  168.     if(p==4 || p==10 || p==14) { bumm(x,y,0); }
  169.     if(p==14){detonate(x,y); }
  170.     if(p==5) { bumm(x,y,3); Adzin=1;}
  171.                 }
  172.   if (p==2 || p==3 || p==8 || p==14) {
  173.    if(!e(c2,y) && !e(c2,c4))
  174.     { set(c2,y,q); set(x,y,0); k(c2,y)=0; if(p==5){Adzin=1;} return;}
  175.    if(!e(c1,y) && !e(c1,c4))
  176.     { set(c1,y,q); set(x,y,0); k(c1,y)=9; if(p==5){Adzin=1;} return;}
  177.   }
  178.   if(q==3 && k(x,y)!=0) {Adzin=1;}
  179.   k(x,y)=0;
  180.   return;
  181.  }
  182. bb=0; manhere=0; uzz=1; ez[0]=7; ez[5]=7;
  183. ez[1]=e(c1,y); ez[2]=e(x,c3); ez[3]=e(c2,y);
  184. ez[4]=e(x,c4);
  185. if(k(x,c3)==1) {ez[2]=6;}
  186.  for(i=1; i<=5; i++)
  187.  {
  188.   if (ez[i]==6) {bb=1;}
  189.   if (ez[i]==10) { manhere=1; }
  190.   if (!ez[i]) {uzz=0;}
  191.  }
  192. if (manhere) {bb=1;}
  193. /* if (uzz && !manhere) {return; } */
  194. if (q==4) {
  195.     if (bb) { bumm(x,c3,0); return; }
  196.     jj=4L; zz=0; ;kz=0; if(k(x,y)>1) {kz=k(x,y)-1;}
  197.     while (jj>0L && !zz)
  198.     { kq=jj+kz-3L;
  199.       if (kq>4) {kq-=4;}
  200.       if (kq<1) {kq+=4;}
  201.       if(!ez[kq]) { zz=1; go(c1,c2,c3,c4,kq,q,x,y); }
  202.       jj--;
  203.     }  return;
  204.  }
  205. if (q==5) {
  206.    if (bb) {bumm(x,c3,3); return; }
  207.    jj=1L; zz=0; kz=0;
  208.   if (k(x,y)>1) { kz=k(x,y)-1; }
  209.   while (jj<5L && !zz)
  210.   { kq=jj+kz-2L;
  211.    if (kq>4) {kq-=4; }
  212.    if (kq<1) {kq+=4; }
  213.    if (!ez[kq]) {zz=1; go(c1,c2,c3,c4,kq,q,x,y); }
  214.    jj++;
  215.   } return;
  216. }
  217. if(q==6) {
  218.   os=0;
  219.   for(i=1;i<5;i++) {
  220.     if (ez[i]<2) { os=1; j=i; }
  221.    }
  222.   clos+=os; oldclos++;
  223.   if (os && (!ez[j] || ez[j])) {
  224.     if( galima(21) )
  225.       { mgo(j,x,y,c1,c2,c3,c4); }
  226.    }
  227.  }
  228. if(q==15) /* Judanti Siena */
  229.  {
  230.   if(!e(c2,y)) {set(c2,y,15); return;}
  231.   if(!e(c1,y)) {set(c1,y,15); k(c1,y)=9; return;}
  232.  }
  233. if(q==16) /* Neauganti magma */
  234.  {
  235.   if(!e(x,c4)) { q=e(x,c3); if(q==2 || q==3)
  236.   { if(galima(11)) { set(x,c4,q); set(x,c3,0); } } }
  237.   return;
  238.  }
  239. j=e(x,c4);
  240. if(q==17) /* Dzin-Dzin Siena */
  241.  {
  242.   q=e(x,c3); if(k(x,c3)==1)
  243.   {
  244.    if(q==2) {set(x,c3,0); if(!j){set(x,c4,3); Adzin=1; }}
  245.    if(q==3) {set(x,c3,0); if(!j){set(x,c4,2); Adzin=1; }}
  246.   } return;
  247.  }
  248. if(q==18) /* Akmenu generatorius */
  249.  { if(!j) {set(x,c4,2); } }
  250. if(q==19) /* Bril. generatorius */
  251.  { if(!j) {set(x,c4,3); } }
  252. if(q==21) { if(k(x,c3)==1) {sprogmina(c1,c2,c3,y); }return; } /* mina */
  253. if(q==23) {BigSuck(x,y,c2,c3);
  254.            } /* Juodoji skyle, SUCK EVERYTHING! */
  255. if(q==14) {
  256.       p=e(x,c4); if(k(x,y)==0){
  257.       if(p==0){set(x,y,0); set(x,c4,14);
  258.                 k(x,c4)=1; return;}
  259.       if(p==2 || p==3 || p==8 || p==q) {
  260.                      if(!e(c2,y) && !e(c2,c4))
  261.                                  {set(c2,y,q); set(x,y,0); return; }
  262.                      if(!e(c1,y) && !e(c1,c4))
  263.                                  {set(c1,y,q); set(x,y,0); return; }
  264.         } /* if p=2,3,8,14 */
  265.                             return; }/* if K */
  266.            if(p==0){set(x,y,0); set(x,c4,14); k(x,c4)=1; return;}
  267.            bumm(x,c3,0); detonate(x,c3); }  /* BOMBA */
  268. return;
  269. }
  270. BigSuck(x,y,c2,c3) /* Juod. skyles siurblys */
  271. SHORT x,y,c2,c3;
  272. {
  273. SHORT i,j;
  274.  for(i=c2;i<x+2;i++) {
  275.    for(j=c3;j<y+2;j++) {
  276.       if(e(i,j)!=7 && e(i,j)!=23 && e(i,j)!=8) {set(i,j,0); }
  277.    }
  278.  }
  279. }
  280. sprogmina(c1,c2,c3,c4) /* Didelis sprogimas */
  281. SHORT c1,c2,c3,c4;
  282. {
  283.  if(e(c2,c3-1)!=7){bumm(c2,c3-1,0);}
  284.  if(e(c1,c3-1)!=7){bumm(c1,c3-1,0);}
  285.  if(e(c2,c4)!=7){bumm(c2,c4,0);}
  286.  if(e(c1,c4)!=7){bumm(c1,c4,0);}
  287. }
  288. bumm(x,y,i)
  289. SHORT x,y,i;
  290. {
  291.  SHORT j,z;
  292.  BUMPOINT++; bummi[BUMPOINT]=i; bummx[BUMPOINT]=x;
  293.  bummy[BUMPOINT]=y;  Abum=1;
  294.  for(j=x-1;j<x+2;j++)
  295.  {
  296.   for(z=y;z<y+3;z++)
  297.   {
  298.    if (e(j,z)!=7) {set(j,z,11); }
  299.   }
  300.  }
  301. }
  302. bumm2()
  303. {
  304. SHORT n;
  305. for(n=1;n<=BUMPOINT;n++) { b2(n); }
  306. BUMPOINT=0; }
  307.  
  308. b2(n)
  309. SHORT n;
  310. {
  311. SHORT x,y,i,j,z;
  312.  x=bummx[n]; y=bummy[n]; i=bummi[n];
  313.  WaitTOF();
  314.  for(j=x-1;j<x+2;j++)
  315.   {
  316.    for(z=y;z<y+3;z++)
  317.     {
  318.      if (ek[z*30+j]!=7) {set(j,z,i); }
  319.     }
  320.   }
  321. }
  322. detonate(x,y) /* Aplinkiniu bombu detonavimas */
  323. SHORT x,y;
  324. {
  325. SHORT i,y2,x2;
  326.  if(x<2){x=2;}
  327.  if(x>27){x=27;}
  328.  if(y<2){y=2;}
  329.  if(y>12){y=10;}
  330.  y2=y-2; x2=y+3;
  331.  for(i=x-2;i<x+3;i++) { if(e(i,y2)==14){
  332.                               k(i,y2)=20; }
  333.                         if(e(i,x2)==14){
  334.                               k(i,x2)=20; }
  335.                       }
  336.  y2=x-2; x2=x+2;
  337.  for(i=y-1;i<y+2;i++) { if(e(y2,i)==14){
  338.                               k(y2,i)=20; }
  339.                         if(e(x2,i)==14){
  340.                               k(x2,i)=20; }
  341.                       }
  342. }
  343.  
  344.